package com.yssoft.controller.supervise;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.yssoft.controller.BaseController;
import com.yssoft.entity.supplier.CirculationInfo;
import com.yssoft.entity.supplier.ProcurementInfo;
import com.yssoft.entity.supplier.ProductCountCustom;
import com.yssoft.entity.supplier.ProductionBatch;
import com.yssoft.entity.supplier.ProductionBatchCustom;
import com.yssoft.entity.supplier.TEnterpriseCustom;
import com.yssoft.service.supervise.TraceabilityQueryService;
@RequestMapping("/supervise/traceabilityQuery")
@Controller
public class TraceabilityQueryController  extends BaseController{
	@Resource
	private  TraceabilityQueryService traceabilityQueryService;
	/**
	 * 
	    * @Title: list
	    * @Description: 溯源查询主界面
	    * @param @param model
	    * @param @return    参数
	    * @return String    返回类型
	    * @throws
	 */
	@RequestMapping(value = "/list")
	public String list(Model model){
		return "supervise/traceabilityQuery/traceabilityQueryList";
	}
	/**
	 * 
	    * @Title: inspectionView
	    * @Description: 进入检验指标页面
	    * @param @param id
	    * @param @param model
	    * @param @return    参数
	    * @return String    返回类型
	    * @throws
	 */
	@RequestMapping(value = "/inspectionView")
	public  String inspectionView(Integer id,Model model) {
		//根据检验报告查询检验明细
		Map<String, Object>  map=traceabilityQueryService.queryiInspectionViewById(id);
	    model.addAttribute("tInspReportDetailList",map.get("tInspReportDetailList"));
	    model.addAttribute("tInspReportAttList",map.get("tInspReportAttList"));
		return "supervise/traceabilityQuery/inspectionView";
	}
	/**
	 * 选择企业列表
	 * @param companyIds
	 * @param model
	 * @return
	 */
    @RequestMapping("queryEnterpriseAll")
    public String queryEnterpriseAll(String companyIds,Model model){
        model.addAttribute("companyIds",companyIds);
        return "supervise/traceabilityQuery/enterpriseListDialog";
    }
 
	/**
	 * 
	    * @Title: traceabilityView
	    * @Description: 溯源查询页面
	    * @param @param model
	    * @param @param custom
	    * @param @return    参数
	    * @return String    返回类型
	    * @throws
	 */
	@RequestMapping(value = "/traceabilityView")
	public String traceabilityView(Model model,ProductionBatch  custom ){
		//商品信息
		Map<String, Object>  product=traceabilityQueryService.queryProductByWorksheetId(custom);
		//企业信息
		TEnterpriseCustom  enterprise=traceabilityQueryService.queryEnterpriseById(custom);
		//批次信息
		ProductionBatchCustom productionBatch=traceabilityQueryService.queryProductionBatchByBatchId(custom);
		//采购信息
		List<ProcurementInfo> procurementInfoList=traceabilityQueryService.queryProcurementInfoListByWorksheetId(custom);
		//生产信息
		List<ProductionInfo > productionInfoList=traceabilityQueryService.queryProductionInfoList(custom);
		//流通信息（订单没有和加工单做关联，所以暂时不能查询该加工单的流通信息，只能查询产品的流通信息，出库过程中没有记录出库的加工批次号）
		List<CirculationInfo > circulationInfoList=traceabilityQueryService.queryCirculationInfoList(custom);
		model.addAttribute("product",product);
		model.addAttribute("enterprise",enterprise);
		model.addAttribute("productionBatch",productionBatch);
		model.addAttribute("procurementInfoList",procurementInfoList);
		model.addAttribute("productionInfoList",productionInfoList);
		model.addAttribute("circulationInfoList",circulationInfoList);
		//当前溯源是按照批次溯源只需要找标签码表并且类型是批次溯源类型即可
		Map<String, Object> urlMap=traceabilityQueryService.queryLabelByWorksheetId(custom);
		if(urlMap!=null && null!=urlMap.get("url") && !"".equals(urlMap.get("url"))) {
			model.addAttribute("imgUrlCode",urlMap.get("url"));
		}
		
		return "supervise/traceabilityQuery/traceabilityView";
	}
	/**
	 * 
	    * @Title: collarMaterialRecordList
	    * @Description: 领料记录
	    * @param @param model
	    * @param @return    参数
	    * @return String    返回类型
	    * @throws
	 */
	@RequestMapping(value = "/collarMaterialRecordList")
	public String collarMaterialRecordList(Model model,String worksheetId,String worksheetCode){
		List<Map<String, Object>> list=traceabilityQueryService.collarMaterialRecordList(worksheetId);
		model.addAttribute("list",list);
		model.addAttribute("worksheetCode",worksheetCode);
		return "supervise/traceabilityQuery/collarMaterialRecordList";
	}
	/**
	 * @方法名称: toInspection
	 * @功能描述: 跳转到检验报告页面
	 * @作者: 洪丰
	 * @创建时间:2018年6月13日 上午11:34:08
	 * @param model
	 * @param inspectionId
	 * @return String
	 */
	@RequestMapping(value = "/toInspection")
	public String toInspection(Model model, Integer recipientId){
        model.addAttribute("recipientId", recipientId);
		return "supervise/traceabilityQuery/inspectionList";
	}
	/**
	 * 查询所有有效产品列表
	 * @param id
	 * @return
	 * @throws IllegalAccessException
	 * @throws ClassNotFoundException
	 */
	@RequestMapping("queryAllProduct")
    @ResponseBody
    public JSONObject queryAllProduct (String enterpriseId) throws IllegalAccessException, ClassNotFoundException{
        return traceabilityQueryService.queryAllProduct( enterpriseId);
    } 
	/**
	 * 根据产品类表查询有效批次
	 * @param id
	 * @return
	 * @throws IllegalAccessException
	 * @throws ClassNotFoundException
	 */
	@RequestMapping("queryAllBatch")
    @ResponseBody
    public JSONObject queryAllBatch (String productId,String code) throws IllegalAccessException, ClassNotFoundException{
        return traceabilityQueryService.queryAllBatch( productId,code);
    } 
	
 
 
}
